local info = require('jelly/info')
local util = require('jelly/util')
local before_cursor, after_cursor
before_cursor, after_cursor = util.before_cursor, util.after_cursor
local tbl_contains
tbl_contains = vim.tbl_contains
local two_char_prefixes = {
  'Ø',
  'Æ',
  'æ',
  'Œ',
  'œ',
  'Ð'
}
local help
help = function()
  local before = before_cursor()
  local after = after_cursor()
  local before_len = before:ulen()
  local after_len = after:ulen()
  if after_len == 0 then
    print('The cursor needs to be on a character')
    return 
  end
  local command = after:uindex(1)
  if before_len ~= 0 then
    local prev_char = before:uindex(before_len)
    if tbl_contains(two_char_prefixes, prev_char) then
      command = prev_char .. command
    end
  end
  if tbl_contains(two_char_prefixes, command) and after_len ~= 1 then
    command = command .. after:uindex(2)
  end
  print(command)
  return print((function()
    if info[command] then
      return info[command].description
    else
      return 'Information not found'
    end
  end)())
end
return {
  help = help
}
